package cn.rengy.web.framework.sys.pub.upload.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.rengy.lang.ResultEntity;
import cn.rengy.web.framework.sys.pub.upload.service.PubFileService;


/**
 * 
 * 
 */
@Controller
@RequestMapping
public class PubFileController {
	private static Logger logger = LoggerFactory.getLogger(PubFileController.class);
	@Autowired
	private PubFileService pubFileService;
	
	
//	@RequestMapping(value="/deleteTestData")
//	@ResponseBody
//    public ResultEntity<?> deleteTestData() {
//		pubFileService.deleteTestData();
//		return ResultEntity.ok();
//    }
	@RequestMapping(value="/authenticated/file/download")
    public void download(HttpServletResponse response,HttpServletRequest request) throws Exception{
		String file_item_id=request.getParameter("file_item_id");
		pubFileService.download(response,file_item_id);
    }
	
	@RequestMapping(value="/file/download")
    public void download1(HttpServletResponse response,HttpServletRequest request) throws Exception{
		String file_item_id=request.getParameter("file_item_id");
		pubFileService.download(response,file_item_id);
    }
	
	@RequestMapping(value="/file/download/query",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity<?> query(@RequestParam("id") Long file_item_id){
		return pubFileService.queryDownload(file_item_id);
	}
//	@RequestMapping(value="/file/downloadByFileId")
//    public void downloadByTarget(HttpServletResponse response,HttpServletRequest request) throws Exception{
//		Long file_id=Long.parseLong(request.getParameter("file_id"));
//		Long target_id=Long.parseLong(request.getParameter("target_id"));
//		pubFileService.download(response,file_id,target_id);
//    }
}
